home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Menu Commands Library.tx Folder / Menu Commands Library.txt next >
Text File  |  1994-05-02  |  5KB  |  126 lines

  1. copy (choose application with prompt "What application would you like to choose a menu item from?") to apl
  2. copy text returned of (display dialog "What is the name of the menu in which the menu item is?" default answer "") to MenuName
  3. copy text returned of (display dialog "What is the name of the item in the " & MenuName & " menu that you would like to choose?" default answer "") to ItemName
  4. doMenuName(apl, MenuName, ItemName)
  5.  
  6. on doMenuName(apl, MenuName, ItemName)
  7.     copy false to foundmenu
  8.     copy false to founditem
  9.     copy (QueryMenuList(apl)) to menulist
  10.     if item 1 of menulist is "error" then
  11.         display dialog (item 2 of menulist) buttons {"Abort"} default button "Abort"
  12.     else
  13.         repeat with cycle from 1 to (number of items in menulist)
  14.             if («class mnti» of item cycle of menulist) is MenuName then
  15.                 copy true to foundmenu
  16.                 copy (QueryMenu(apl, («class mnid» of item cycle of menulist))) to itemlist
  17.                 if item 1 of itemlist is "error" then
  18.                     display dialog (item 2 of itemlist) buttons {"Abort"} default button "Abort"
  19.                 else
  20.                     repeat with cycle2 from 1 to (number of items in itemlist)
  21.                         if («class mite» of item cycle2 of itemlist) is ItemName then
  22.                             copy true to founditem
  23.                             copy (DoMenuItem(apl, («class mnid» of item cycle of menulist), («class miid» of item cycle2 of itemlist))) to theResult
  24.                             if item 1 of theResult is "error" then
  25.                                 display dialog (item 2 of theResult) buttons {"Abort"} default button "Abort"
  26.                             end if
  27.                             exit repeat
  28.                         end if
  29.                     end repeat
  30.                 end if
  31.                 exit repeat
  32.             end if
  33.         end repeat
  34.     end if
  35.     if foundmenu is false then
  36.         display dialog "The menu \"" & MenuName & "\" was not found in the application \"" & apl & "\"."
  37.     end if
  38.     if (founditem is false) and (foundmenu is true) then
  39.         display dialog "The menu item \"" & ItemName & "\" was not found in the menu \"" & MenuName & "\" in the application \"" & apl & "\"."
  40.     end if
  41. end doMenuName
  42.  
  43. on QueryMenuList(apl)
  44.     try
  45.         tell apl
  46.             return («event Mænuqmn#»)
  47.         end tell
  48.     on error (errID)
  49.         copy word ((number of words in errID) - 2) of errID to errID
  50.         if errID = "126" then
  51.             copy "A Menu Events error occurred. The specified application (" & apl & ") has no menu bar." to errText
  52.         else
  53.             copy "" to errText
  54.         end if
  55.         if errText is "" then
  56.             return errID
  57.         else
  58.             return {"error", errText}
  59.         end if
  60.     end try
  61. end QueryMenuList
  62.  
  63. on QueryMenu(apl, MenuID)
  64.     try
  65.         tell apl
  66.             return («event Mænuqmn » given «class mnid»:MenuID)
  67.         end tell
  68.     on error (errID)
  69.         copy "" to errText
  70.         copy word ((number of words in errID) - 2) of errID to errID
  71.         if errID = "126" then
  72.             copy "A Menu Events error occurred. The specified application (" & apl & ") has no menu bar." to errText
  73.         end if
  74.         if errID = "21000" then
  75.             copy "A Menu Events error occurred. The specified application (" & apl & ") has no such menu (menu id " & MenuID & " was specified)." to errText
  76.         end if
  77.         if errID = "21004" then
  78.             copy "A Menu Events error occurred. The specified application (" & apl & ") does not support High Level Events." to errText
  79.         end if
  80.         if errText = "" then
  81.             return errID
  82.         else
  83.             return {"error", errText}
  84.         end if
  85.     end try
  86. end QueryMenu
  87.  
  88. on DoMenuItem(apl, MenuID, MenuItemID)
  89.     try
  90.         tell apl
  91.             «event Mænusemi» given «class mnid»:MenuID, «class miid»:MenuItemID
  92.         end tell
  93.         return {""}
  94.     on error (errID)
  95.         copy word ((number of words in errID) - 2) of errID to errID
  96.         copy "" to errText
  97.         if errID = "126" then
  98.             copy "A Menu Events error occurred. The specified application (" & apl & ") has no menu bar." to errText
  99.         end if
  100.         if errID = "1713" then
  101.             copy "A Menu Events error occurred. The specified application (" & apl & ¬
  102.                 ") is refusing to interact with other processes, or (if Menu Events extension is locked) with remote processes." to errText
  103.         end if
  104.         if errID = "21000" then
  105.             copy "A Menu Events error occurred. The specified application (" & apl & ") has no such menu (menu id " & MenuID & " was specified)." to errText
  106.         end if
  107.         if errID = "21001" then
  108.             copy "A Menu Events error occurred. The specified application (" & apl & ") has no such menu item (menu item id " & MenuItemID & " was specified)." to errText
  109.         end if
  110.         if errID = "21002" then
  111.             copy "A Menu Events error occurred. The specified application (" & apl & ") has menu item id " & MenuItemID & " of menu id " & MenuID & " disabled." to errText
  112.         end if
  113.         if errID = "21003" then
  114.             copy "A Menu Events error occurred. The specified application (" & apl & ") has another Menu Event pending." to errText
  115.         end if
  116.         if errID = "21004" then
  117.             copy "A Menu Events error occurred. The specified application (" & apl & ") does not support High Level Events." to errText
  118.         end if
  119.         if errText is "" then
  120.             return errID
  121.         else
  122.             return {"error", errText}
  123.         end if
  124.     end try
  125. end DoMenuItem
  126.